/**
  ******************************************************************************
  * @file    app_sharebuff.c
  * @author  tuancheng_Zero
  * @version V0.1
  * @date    08/28/2024
  * @brief   share buff file
  ******************************************************************************
*/
#include <includes.h>
#include "app_sharebuffer.h"
#include "avr_pcfg.h"
#include "workFlow_cfg.h"
#include "PrimeMotor_Driver.h"
#include "TempControl_Driver.h"

// 全局变量
RemoteDataAddress_ST share_RemoteDataAddress_st = {0};   //远程数据
RealTimeStatusData_ST share_RealTimeData_st = {0};      // 实时状态数据
RealTimeStatusData_CKP share_RealTimeData_ckp = {0};      // 实时状态数据(串口屏)
EstaMagnData_ST share_EstaMagnData_st = {0};            // 建磁电压数据
CeilingExciData_ST share_CeilingExciData_st = {0};      // 极限励磁数据
VolatilityData_ST share_VolatilityData_st = {0};        // 波动率数据
UnderFreqData_ST share_UnderFreqData_st = {0};          // 低频保护数据
StartStopData_ST share_StartStopData_st = {0};          // 启停数据
UploadData_ST share_UploadData_st = {0};                // 整定测试数据
SuddenUnloadData_ST share_SuddenUnloadData_st = {0};    // 突卸测试数据
ParameterCfgData_ST share_parameterCfgData_st = {0};    // 参数配置数据
TempConfig_ST share_TempConfig_st = {0};                // 临时配置数据
CurveDataBuff_ST share_CurveDataBuff_1 = {0};           // 曲线临时缓冲区1
CurveDataBuff_ST share_CurveDataBuff_2 = {0};           // 曲线临时缓冲区2
CurveDataBuff_ST share_CurveDataBuff_3 = {0};           // 曲线临时缓冲区3
CurveDataBuff_ST share_CurveDataBuff_4 = {0};           // 曲线临时缓冲区4
CurveDataBuff_ST share_CurveDataBuff_5 = {0};           // 曲线临时缓冲区5


/// @brief 共享缓冲初始化
/// @param  none
void sharebuffer_Init(void){
    /* 建压数据初始化 */
    share_EstaMagnData_st.baseData_st.ReportPage_number = 0x01;
    share_EstaMagnData_st.curveData_st.GenVoltDataCurve_Addr = SRAM_EstaMagn_GenVoltDataCurve_Addr;
    share_EstaMagnData_st.curveData_st.PowerVoltDataCurve_Addr = SRAM_EstaMagn_PowerVoltDataCurve_Addr;
    share_EstaMagnData_st.curveData_st.GenExci_VoltDataCurve_Addr = SRAM_EstaMagn_GenExci_VoltDataCurve_Addr;
    share_EstaMagnData_st.curveData_st.GenExci_CurrentDataCurve_Addr = SRAM_EstaMagn_GenExci_CurrentDataCurve_Addr;

    /* 极限励磁数据初始化 */
    share_CeilingExciData_st.baseData_st.ReportPage_number = 0x02;
    share_CeilingExciData_st.curveData_st.GenVoltDataCurve_Addr = SRAM_CeilingExci_GenVoltDataCurve_Addr;
    share_CeilingExciData_st.curveData_st.GenExci_VoltDataCurve_Addr = SRAM_CeilingExci_GenExci_VoltDataCurve_Addr;
    share_CeilingExciData_st.curveData_st.GenExci_CurrentDataCurve_Addr = SRAM_CeilingExci_GenExci_CurrentDataCurve_Addr;

    /* 波动率数据初始化 */
    share_VolatilityData_st.baseData_st.ReportPage_number = 0x03;
    share_VolatilityData_st.curveData_st.VoltDataCurve_U_Addr = SRAM_Volatility_VoltDataCurve_U_Addr;
    share_VolatilityData_st.curveData_st.VoltDataCurve_V_Addr = SRAM_Volatility_VoltDataCurve_V_Addr;
    share_VolatilityData_st.curveData_st.VoltDataCurve_W_Addr = SRAM_Volatility_VoltDataCurve_W_Addr;
    share_VolatilityData_st.curveData_st.VoltDataCurve_Addr = SRAM_Volatility_VoltDataCurve_Addr;
    share_VolatilityData_st.curveData_st.FreqDataCurve_Addr = SRAM_Volatility_FreqDataCurve_Addr;
    
    /* 低频保护数据初始化 */
    share_UnderFreqData_st.baseData_st.ReportPage_number = 0x04;
    share_UnderFreqData_st.curveData_st.GenVoltDataCurve_Addr = SRAM_UnderFreq_GenVoltDataCurve_Addr;
    share_UnderFreqData_st.curveData_st.GenExci_VoltDataCurve_Addr = SRAM_UnderFreq_GenExci_VoltDataCurve_Addr;
    share_UnderFreqData_st.curveData_st.GenExci_CurrentDataCurve_Addr = SRAM_UnderFreq_GenExci_CurrentDataCurve_Addr;
    share_UnderFreqData_st.curveData_st.GenFreqDataCurve_Addr = SRAM_UnderFreq_GenFreqDataCurve_Addr;
    
    /* 启停数据初始化 */
    share_StartStopData_st.baseData_st.ReportPage_number = 0x05;
    share_StartStopData_st.curveData_st.GenVoltCurve_Addr = SRAM_StartStop_GenVoltCurve_Addr;
    share_StartStopData_st.curveData_st.ExciVoltCurve_Addr = SRAM_StartStop_ExciVoltCurve_Addr;
    share_StartStopData_st.curveData_st.ExciCurrentCurve_Addr = SRAM_StartStop_ExciCurrentCurve_Addr;
    share_StartStopData_st.curveData_st.GenFreqCurve_Addr = SRAM_StartStop_GenFreqCurve_Addr;

    /* 整定数据初始化 */
    share_UploadData_st.baseData_st.ReportPage_number = 0x07;
    share_UploadData_st.curveData_st.VoltDataCurve_U_Addr = SRAM_Upload_VoltDataCurve_U_Addr;
    share_UploadData_st.curveData_st.VoltDataCurve_V_Addr = SRAM_Upload_VoltDataCurve_V_Addr;
    share_UploadData_st.curveData_st.VoltDataCurve_W_Addr = SRAM_Upload_VoltDataCurve_W_Addr;
    share_UploadData_st.curveData_st.VoltDataCurve_Addr = SRAM_Upload_VoltDataCurve_Addr;
    share_UploadData_st.curveData_st.FreqDataCurve_Addr = SRAM_Upload_FreqDataCurve_Addr;
    
    /* 突卸数据初始化 */
    share_SuddenUnloadData_st.baseData_st.ReportPage_number = 0x08;
    share_SuddenUnloadData_st.curveData_st.VoltDataCurve_U_Addr = SRAM_SuddenUnload_VoltDataCurve_U_Addr;
    share_SuddenUnloadData_st.curveData_st.VoltDataCurve_V_Addr = SRAM_SuddenUnload_VoltDataCurve_V_Addr;
    share_SuddenUnloadData_st.curveData_st.VoltDataCurve_W_Addr = SRAM_SuddenUnload_VoltDataCurve_W_Addr;
    share_SuddenUnloadData_st.curveData_st.VoltDataCurve_Addr = SRAM_SuddenUnload_VoltDataCurve_Addr;
    share_SuddenUnloadData_st.curveData_st.FreqDataCurve_Addr = SRAM_SuddenUnload_FreqDataCurve_Addr;

    /* 配置页面数据初始化 */
    share_parameterCfgData_st.ReportPage_number = 0x09;

    /* 临时配置页面初始化 */
    share_TempConfig_st.deviceControl_st.ReportPage_number = 0x0A;
    share_TempConfig_st.procedurePara_st.LoginStatus = 3;
    share_TempConfig_st.procedurePara_st.DeviceNumber = 201;
}


void sharebuff_RealTimeDataUpdate_CKP(void){
  // share_RealTimeData_ckp.GenPhaVolt_U                  =123;
  // share_RealTimeData_ckp.GenPhaVolt_V                  =123;
  // share_RealTimeData_ckp.GenPhaVolt_W                  =123;
  share_RealTimeData_ckp.GenPhaVolt_U                  =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL1*10;
  share_RealTimeData_ckp.GenPhaVolt_V                  =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL2*10;
  share_RealTimeData_ckp.GenPhaVolt_W                  =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL3*10;
  share_RealTimeData_ckp.GenPhaVolt_average            =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenPhaseVoltAverage*10;
  share_RealTimeData_ckp.GenLineVolt_Uab               =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenLineVoltL12*10;
  share_RealTimeData_ckp.GenLineVolt_Ubc               =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenLineVoltL23*10;
  share_RealTimeData_ckp.GenLineVolt_Uca               =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenLineVoltL31*10;
  share_RealTimeData_ckp.GenLineVolt_average           =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenLineVoltAverage*10;
  share_RealTimeData_ckp.GenLineVolt_GenCurrent_U      =(uint16_t)ACAD_RTGlobalData.PowerData.GenCurrL1*10;
  share_RealTimeData_ckp.GenLineVolt_GenCurrent_V      =(uint16_t)ACAD_RTGlobalData.PowerData.GenCurrL2*10;
  share_RealTimeData_ckp.GenLineVolt_GenCurrent_W      =(uint16_t)ACAD_RTGlobalData.PowerData.GenCurrL3*10;
  share_RealTimeData_ckp.GenLineVolt_GenCurrent_average=(uint16_t)ACAD_RTGlobalData.PowerData.GenCurrLAverage*10;
  share_RealTimeData_ckp.GenActiPower_U                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerP1*10;
  share_RealTimeData_ckp.GenActiPower_V                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerP2*10;
  share_RealTimeData_ckp.GenActiPower_W                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerP3*10;
  share_RealTimeData_ckp.GenActiPower_total            =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerPTotal*10;
  share_RealTimeData_ckp.GenReacPower_U                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerQ1*10;
  share_RealTimeData_ckp.GenReacPower_V                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerQ2*10;
  share_RealTimeData_ckp.GenReacPower_W                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerQ3*10;
  share_RealTimeData_ckp.GenReacPower_total            =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerQTotal*10;
  share_RealTimeData_ckp.GenAppePower_U                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerS1*10;
  share_RealTimeData_ckp.GenAppePower_V                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerS2*10;
  share_RealTimeData_ckp.GenAppePower_W                =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerS3*10;
  share_RealTimeData_ckp.GenAppePower_total            =(uint16_t)ACAD_RTGlobalData.PowerData.GenPowerSTotal*10;
  share_RealTimeData_ckp.PowFactor_U                   =(uint16_t)ACAD_RTGlobalData.PowerData.GenPFL1*10;
  share_RealTimeData_ckp.PowFactor_V                   =(uint16_t)ACAD_RTGlobalData.PowerData.GenPFL2*10;
  share_RealTimeData_ckp.PowFactor_W                   =(uint16_t)ACAD_RTGlobalData.PowerData.GenPFL3*10;
  share_RealTimeData_ckp.PowFactor_average             =(uint16_t)ACAD_RTGlobalData.PowerData.GenPFAverage*10;
  share_RealTimeData_ckp.GenFrequency                  =(uint16_t)ACAD_RTGlobalData.GenVoltData.GenFreqAverage*10;
  share_RealTimeData_ckp.LoadExci_volt                 =(uint16_t)ACAD_RTGlobalData.LoadExcitationData.ExcitationVolt*10;
  share_RealTimeData_ckp.LoadExci_current              =(uint16_t)ACAD_RTGlobalData.LoadExcitationData.ExcitationCurr*10;
  share_RealTimeData_ckp.Operate_CurrProc              =ShareBuffer_WorkflowMode;
  share_RealTimeData_ckp.CurrProcCountdown             =(uint16_t)CurrProcCountdown/WorkFlowTimingFreq;
  share_RealTimeData_ckp.OperMode                      =ShareBuffer_WorkflowRunMode;
  share_RealTimeData_ckp.LimitAlarm                    =LIMITAlarm;
  share_RealTimeData_ckp.TestProceAlarm1               =ControlAlarm&0xFFFF;
  share_RealTimeData_ckp.TestProceAlarm2               =(ControlAlarm>>16)&0xFFFF;
  share_RealTimeData_ckp.TestProceAlarm3               =(ControlAlarm>>32)&0xFFFF;
  share_RealTimeData_ckp.TestProceAlarm4               =(ControlAlarm>>48)&0xFFFF;
  // share_RealTimeData_ckp.tm_year
  // share_RealTimeData_ckp.tm_mon 
  // share_RealTimeData_ckp.tm_mday
  // share_RealTimeData_ckp.tm_hour
  // share_RealTimeData_ckp.tm_min 
  // share_RealTimeData_ckp.tm_sec 
  share_RealTimeData_ckp.Runing_Time                   =0;
  // memcpy(share_RealTimeData_ckp.Product_number, share_TempConfig_st.procedurePara_st.Product_number, sizeof(share_TempConfig_st.procedurePara_st.Product_number));
  share_RealTimeData_ckp.BuildVoltBefore        = (uint16_t)ACAD_RTGlobalData.BuildVoltData.BuildVoltBEF*10;
  share_RealTimeData_ckp.BuildVoltAfter         = (uint16_t)ACAD_RTGlobalData.BuildVoltData.BuildVoltAFT*10;
  share_RealTimeData_ckp.PrimeMotorFreq         = pMotorStatus_st.curFreq*10;
  share_RealTimeData_ckp.Operate_Teststatus     = FlowDataStatus;
}

/// @brief 实时数据更新函数
/// @param  none
void sharebuff_RealTimeDataUpdate(void){
    OS_CPU_SR cpu_sr;
    OS_ENTER_CRITICAL(); // 进入临界区配置实时数据

    share_RealTimeData_st.Update_Count           = 0;
    share_RealTimeData_st.InputLine_Mode         = share_parameterCfgData_st.baseData_st.InputLine_Mode;
    share_RealTimeData_st.Language_Mode          = share_parameterCfgData_st.baseData_st.Language_Mode;
    share_RealTimeData_st.WaveRecord_rate        = share_parameterCfgData_st.baseData_st.WaveRecord_rate;
    share_RealTimeData_st.TransientResponse_rate = share_parameterCfgData_st.baseData_st.TransientResponse_rate;
    share_RealTimeData_st.EnergyAcc_time         = 0;
    share_RealTimeData_st.CurrProcCountdown      = (uint16_t)CurrProcCountdown/WorkFlowTimingFreq;
    share_RealTimeData_st.RatedLineVoltage       = share_parameterCfgData_st.nominalCfg_st.RatedLineVolt;
    share_RealTimeData_st.RatedPhaseVoltage      = share_parameterCfgData_st.nominalCfg_st.RatedPhaseVolt;
    share_RealTimeData_st.RatedCurrent           = share_parameterCfgData_st.nominalCfg_st.RatedFrequency;
    share_RealTimeData_st.RatedFrequency         = share_parameterCfgData_st.nominalCfg_st.RatedCurrent;
    share_RealTimeData_st.VoltTole_band          = 0.0;
    share_RealTimeData_st.FreqTole_band          = 0.0;
    share_RealTimeData_st.TimeArea               = share_parameterCfgData_st.baseData_st.TimeArea;
    share_RealTimeData_st.CurrentDateTime        = rtc_GetRtcTimeStamp();
    share_RealTimeData_st.SelfTest_status        = Alarm_RTGlobalData;
    share_RealTimeData_st.Operate_Teststatus     = FlowDataStatus;
    share_RealTimeData_st.Operate_CurrProc       = ShareBuffer_WorkflowMode;
    share_RealTimeData_st.LockDateTime           = 0;
    share_RealTimeData_st.Runing_Time            = 0;
    share_RealTimeData_st.GenPhaVolt_U           = ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL1;
    share_RealTimeData_st.GenPhaVolt_V           = ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL2;
    share_RealTimeData_st.GenPhaVolt_W           = ACAD_RTGlobalData.GenVoltData.GenPhaseVoltL3;
    share_RealTimeData_st.GenPhaVolt_average     = ACAD_RTGlobalData.GenVoltData.GenPhaseVoltAverage;
    share_RealTimeData_st.GenLineVolt_Uab        = ACAD_RTGlobalData.GenVoltData.GenLineVoltL12;
    share_RealTimeData_st.GenLineVolt_Ubc        = ACAD_RTGlobalData.GenVoltData.GenLineVoltL23;
    share_RealTimeData_st.GenLineVolt_Uca        = ACAD_RTGlobalData.GenVoltData.GenLineVoltL31;
    share_RealTimeData_st.GenLineVolt_average    = ACAD_RTGlobalData.GenVoltData.GenLineVoltAverage;
    share_RealTimeData_st.GenFrequency           = ACAD_RTGlobalData.GenVoltData.GenFreqAverage;
    share_RealTimeData_st.GenCurrent_U           = ACAD_RTGlobalData.PowerData.GenCurrL1;
    share_RealTimeData_st.GenCurrent_V           = ACAD_RTGlobalData.PowerData.GenCurrL2;
    share_RealTimeData_st.GenCurrent_W           = ACAD_RTGlobalData.PowerData.GenCurrL3;
    share_RealTimeData_st.GenCurrent_average     = ACAD_RTGlobalData.PowerData.GenCurrLAverage;
    share_RealTimeData_st.GenActiPower_U         = ACAD_RTGlobalData.PowerData.GenPowerP1;
    share_RealTimeData_st.GenActiPower_V         = ACAD_RTGlobalData.PowerData.GenPowerP2;
    share_RealTimeData_st.GenActiPower_W         = ACAD_RTGlobalData.PowerData.GenPowerP3;
    share_RealTimeData_st.GenActiPower_total     = ACAD_RTGlobalData.PowerData.GenPowerPTotal;
    share_RealTimeData_st.GenReacPower_U         = ACAD_RTGlobalData.PowerData.GenPowerQ1;
    share_RealTimeData_st.GenReacPower_V         = ACAD_RTGlobalData.PowerData.GenPowerQ2;
    share_RealTimeData_st.GenReacPower_W         = ACAD_RTGlobalData.PowerData.GenPowerQ3;
    share_RealTimeData_st.GenReacPower_total     = ACAD_RTGlobalData.PowerData.GenPowerQTotal;
    share_RealTimeData_st.GenAppePower_U         = ACAD_RTGlobalData.PowerData.GenPowerS1;
    share_RealTimeData_st.GenAppePower_V         = ACAD_RTGlobalData.PowerData.GenPowerS2;
    share_RealTimeData_st.GenAppePower_W         = ACAD_RTGlobalData.PowerData.GenPowerS3;
    share_RealTimeData_st.GenAppePower_total     = ACAD_RTGlobalData.PowerData.GenPowerSTotal;
    share_RealTimeData_st.PowFactor_U            = ACAD_RTGlobalData.PowerData.GenPFL1;
    share_RealTimeData_st.PowFactor_V            = ACAD_RTGlobalData.PowerData.GenPFL2;
    share_RealTimeData_st.PowFactor_W            = ACAD_RTGlobalData.PowerData.GenPFL3;
    share_RealTimeData_st.PowFactor_average      = ACAD_RTGlobalData.PowerData.GenPFAverage;
    share_RealTimeData_st.GenExci_volt           = ACAD_RTGlobalData.GenExcitationData.ExcitationVolt;
    share_RealTimeData_st.GenExci_current        = ACAD_RTGlobalData.GenExcitationData.ExcitationCurr;
    share_RealTimeData_st.GenExci_power          = ACAD_RTGlobalData.GenExcitationData.ExcitationPower;
    share_RealTimeData_st.LoadPhaVolt_U          = ACAD_RTGlobalData.LoadVoltData.GenPhaseVoltL1;
    share_RealTimeData_st.LoadPhaVolt_V          = ACAD_RTGlobalData.LoadVoltData.GenPhaseVoltL2;
    share_RealTimeData_st.LoadPhaVolt_W          = ACAD_RTGlobalData.LoadVoltData.GenPhaseVoltL3;
    share_RealTimeData_st.LoadPhaVolt_average    = ACAD_RTGlobalData.LoadVoltData.GenPhaseVoltAverage;
    share_RealTimeData_st.LoadLineVolt_Uab       = ACAD_RTGlobalData.LoadVoltData.GenLineVoltL12;
    share_RealTimeData_st.LoadLineVolt_Ubc       = ACAD_RTGlobalData.LoadVoltData.GenLineVoltL23;
    share_RealTimeData_st.LoadLineVolt_Uca       = ACAD_RTGlobalData.LoadVoltData.GenLineVoltL31;
    share_RealTimeData_st.LoadLineVolt_average   = ACAD_RTGlobalData.LoadVoltData.GenLineVoltAverage;
    share_RealTimeData_st.LoadFrequency          = ACAD_RTGlobalData.LoadVoltData.GenFreqAverage;
    share_RealTimeData_st.LoadPhaseDiff_U2_1     = ACAD_RTGlobalData.LoadVoltData.GenPhaseDiffU2U1;
    share_RealTimeData_st.LoadPhaseDiff_U3_2     = ACAD_RTGlobalData.LoadVoltData.GenPhaseDiffU3U1;
    share_RealTimeData_st.LoadExci_volt          = ACAD_RTGlobalData.LoadExcitationData.ExcitationVolt;
    share_RealTimeData_st.LoadExci_current       = ACAD_RTGlobalData.LoadExcitationData.ExcitationCurr;
    share_RealTimeData_st.LoadExci_power         = ACAD_RTGlobalData.LoadExcitationData.ExcitationPower;
    share_RealTimeData_st.AccWork_total          = 0;
    share_RealTimeData_st.AccActiEnergy_U        = 220.5;
    share_RealTimeData_st.AccActiEnergy_V        = 55.0;
    share_RealTimeData_st.AccActiEnergy_W        = 26.0;
    share_RealTimeData_st.AccActiEnergy_total    = 45.0;
    share_RealTimeData_st.AccReacEnergy_U        = 120.0;
    share_RealTimeData_st.AccReacEnergy_V        = 56.0;
    share_RealTimeData_st.AccReacEnergy_W        = 66.0;
    share_RealTimeData_st.AccReacEnergy_total    = 70.0;
    share_RealTimeData_st.GenVolt_imbalance      = 65.0;
    share_RealTimeData_st.ZeroSquence_volt       = 60.0;
    share_RealTimeData_st.NegaSquence_volt       = 50.0;
    share_RealTimeData_st.PosiSquence_volt       = 50.0;
    share_RealTimeData_st.GenPhaseDiff_U2_1      = ACAD_RTGlobalData.GenVoltData.GenPhaseDiffU2U1;
    share_RealTimeData_st.GenPhaseDiff_U3_2      = ACAD_RTGlobalData.GenVoltData.GenPhaseDiffU3U1;
    share_RealTimeData_st.CurrentToVoltPhas_U    = 20.0;
    share_RealTimeData_st.CurrentToVoltPhas_V    = 20.0;
    share_RealTimeData_st.CurrentToVoltPhas_W    = 20.0;
    share_RealTimeData_st.VoltDiff_RelaLoad_U    = ACAD_RTGlobalData.SyncData.VoltDiffU1;
    share_RealTimeData_st.VoltDiff_RelaLoad_V    = ACAD_RTGlobalData.SyncData.VoltDiffU2;
    share_RealTimeData_st.VoltDiff_RelaLoad_W    = ACAD_RTGlobalData.SyncData.VoltDiffU3;
    share_RealTimeData_st.VoltDiff_RelaLoad      = ACAD_RTGlobalData.SyncData.VoltDiffAverage;
    share_RealTimeData_st.PhaseDiff_RelaLoad_U   = ACAD_RTGlobalData.SyncData.PhaseDiffU1;
    share_RealTimeData_st.PhaseDiff_RelaLoad_V   = ACAD_RTGlobalData.SyncData.PhaseDiffU2;
    share_RealTimeData_st.PhaseDiff_RelaLoad_W   = ACAD_RTGlobalData.SyncData.PhaseDiffU3;
    share_RealTimeData_st.PhaseDiff_RelaLoad     = ACAD_RTGlobalData.SyncData.PhaseDiffAverage;
    share_RealTimeData_st.OperMode               = ShareBuffer_WorkflowRunMode;
    share_RealTimeData_st.TestProceAlarm         = ControlAlarm;
    share_RealTimeData_st.TestDeviceFlag         = 1;
    share_RealTimeData_st.SyncClosingStatus      = switchState;
    share_RealTimeData_st.LimitAlarm             = LIMITAlarm;
    share_RealTimeData_st.BuildVoltBefore        = ACAD_RTGlobalData.BuildVoltData.BuildVoltBEF;
    share_RealTimeData_st.BuildVoltAfter         = ACAD_RTGlobalData.BuildVoltData.BuildVoltAFT;
    share_RealTimeData_st.PrimeMotorFreq         = pMotorStatus_st.curFreq;
    OS_EXIT_CRITICAL();
}

/* Exchange Data Content Value */
uint8_t GetShareBufferDataContent(void *Pevent, uint8_t OperaType, uint8_t *Source)
{
	uint8_t os_err, Result;

	/*****************************/
	/* Request control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
		OSSemPend((OS_EVENT *)Pevent, 0, &os_err);

	Result = *Source;

	/*****************************/
	/* Release control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
	{
		if (OSSemPost((OS_EVENT *)Pevent) != OS_ERR_NONE)
			SYS_DebugERROR; /* Error- Only for Debug */
	}

	return (Result);
}

/* Fill Data Content Value */
uint8_t FillShareBufferDataContent(void *Pevent, uint8_t OperaType, uint8_t *Source, uint8_t Value, uint8_t Number)
{
	uint8_t os_err;

	/*****************************/
	/* Request control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
		OSSemPend((OS_EVENT *)Pevent, 0, &os_err);

	for (; Number > 0; Number--)
		*(Source++) = Value;

	/*****************************/
	/* Release control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
	{
		if (OSSemPost((OS_EVENT *)Pevent) != OS_ERR_NONE)
		{
			SYS_DebugERROR; /* Error- Only for Debug */
			return (DEF_FALSE);
		}
	}

	return (DEF_TRUE);
}


/**
  * @brief  Modify Flag Status
  * @param  none
  * @return none.
  */
uint8_t SetOSFlagsForNewInform(OS_FLAG_GRP *Pevent,OS_FLAGS Flags)
{
  uint8_t os_err;
  
	OSFlagPost(Pevent,Flags,OS_FLAG_SET,&os_err);
  if(os_err!=OS_ERR_NONE)
  {
    SYS_DebugERROR;
    return(DEF_FALSE);
  }
  
  return(DEF_TRUE);
}
/**
 * @brief  Get Flag Status
 * @param  none
 * @return none.
 */
uint8_t GetFlagShareBufferDataContent(void *Pevent, uint8_t OperaType, uint8_t *Source, uint16_t BitSequence)
{
	uint8_t os_err;
	uint8_t y, x;
	uint8_t bitx;
	uint8_t BitStatus;

	y = (uint8_t)(BitSequence >> 3);
	x = (uint8_t)(BitSequence & 0x07);
	bitx = (uint8_t)(1 << x);

	/*****************************/
	/* Request control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
		OSSemPend((OS_EVENT *)Pevent, 0, &os_err);

	BitStatus = (*(Source + y)) & bitx;

	/*****************************/
	/* Release control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
	{
		if (OSSemPost((OS_EVENT *)Pevent) != OS_ERR_NONE)
			SYS_DebugERROR; /* Error- Only for Debug */
	}

	return (BitStatus);
}


/**
 * @brief  Modify Flag Status
 * @ BitSequence 的最后3位是字节中的位号，前面的13位是所属字节编号
 * @return none.
 */
uint8_t ModifyFlagShareBufferDataContent(void *Pevent, uint8_t OperaType, uint8_t *Source, uint16_t BitSequence, uint8_t OperaOpt)
{
	uint8_t os_err;
	uint8_t y, x;
	uint8_t bitx;

	y = (uint8_t)(BitSequence >> 3);   // 前面的13位是所属字节编号
	x = (uint8_t)(BitSequence & 0x07); // 最后3位是字节中的位号
	bitx = (uint8_t)(1 << x);		   //

	/*****************************/
	/* Request control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
		OSSemPend((OS_EVENT *)Pevent, 0, &os_err);

	if (OperaOpt == BitOperaOpt_Set)
		*(Source + y) |= bitx; // Source本身只是单字节数据的地址，加上y后，就相当于跳动了y个地址，并修改这个地址的字节的对应比特位，非常的巧妙。
	else if (OperaOpt == BitOperaOpt_Clr)
		*(Source + y) &= ~bitx;
	else if (OperaOpt == BitOperaOpt_Nor)
		*(Source + y) ^= bitx;

	/*****************************/
	/* Release control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
	{
		if (OSSemPost((OS_EVENT *)Pevent) != OS_ERR_NONE)
		{
			SYS_DebugERROR; /* Error- Only for Debug */
			return (DEF_FALSE);
		}
	}

	return (DEF_TRUE);
}

uint8_t ClrOSFlagsForNewInform(OS_FLAG_GRP *Pevent,OS_FLAGS Flags)
{
  uint8_t os_err;
  
	OSFlagPost(Pevent,Flags,OS_FLAG_CLR,&os_err);
  if(os_err!=OS_ERR_NONE)
  {
    SYS_DebugERROR;
    return(DEF_FALSE);
  }
  return(DEF_TRUE);
}

/* Exchange Data Content Value */
uint8_t ExchangeShareBufferDataContent(void *Pevent, uint8_t OperaType, uint8_t *Target, uint8_t *Source, uint8_t Number)
{
	uint8_t os_err;

	/*****************************/
	/* Request control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
		OSSemPend((OS_EVENT *)Pevent, 0, &os_err);

	for (; Number > 0; Number--)
		*(Target++) = *(Source++);

	/*****************************/
	/* Release control right*/
	/* Exchange Buffer Value */
	if (OperaType == CfgOperaType_OSSem)
	{
		if (OSSemPost((OS_EVENT *)Pevent) != OS_ERR_NONE)
		{
			SYS_DebugERROR; /* Error- Only for Debug */
			return (DEF_FALSE);
		}
	}

	return (DEF_TRUE);
}